package com.thinkcube.edutainment.adapters;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.thinkcube.edutainment.R;
import com.thinkcube.edutainment.domain.data.LessonData;

public class LessonBarAdapter extends ArrayAdapter<String> {

	private Context context;
	private String[] values;
	private ArrayList<LessonData> lessons;
	int selectedIntdex;

	public LessonBarAdapter(Context context, String[] values,
			ArrayList<LessonData> lessons, int selectedIntdex) {
		super(context, R.layout.lesson_bar_item, values);
		this.lessons = lessons;
		this.context = context;
		this.values = values;
		this.selectedIntdex = selectedIntdex;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		View view = convertView;
		ViewHolder holder;
		// TextView v1;
		TextView v2;
		LinearLayout vlin;
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = inflater.inflate(R.layout.lesson_bar_item, parent, false);
			holder = new ViewHolder();
			// v1=(TextView) view.findViewById(R.id.lesson_no);
			v2 = (TextView) view.findViewById(R.id.lesson_title);
			vlin = (LinearLayout) view.findViewById(R.id.item_select);
			// holder.lesson=v1;
			holder.item = vlin;
			holder.lessonNo = v2;
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		/*
		 * TextView lessonNo= (TextView) view.findViewById(R.id.lesson_no);
		 * TextView lesson=(TextView) view.findViewById(R.id.lesson_title);
		 * lessonNo.setText(lessons.get(position).getLessonCode());
		 * lesson.setText(lessons.get(position).getLessonTitle());
		 */

		// holder.lessonNo.setText(lessons.get(position).getLessonCode());
		holder.lessonNo.setText(lessons.get(position).getLessonTitle());

		// System.out.println("lesson code >>"+lessons.get(position).getLessonCode());
		// System.out.println("lesson title >>"+lessons.get(position).getLessonTitle());
		// System.out.println("lesson id >>"+lessons.get(position).getLessonId());

		if (selectedIntdex != -1 && position == selectedIntdex) {
			// view.setBackgroundColor(Color.BLACK);
			view.setBackgroundResource(R.drawable.nav_active);
		} else

		{
			view.setBackgroundResource(Color.TRANSPARENT);
		}
		return view;
	}

	private class ViewHolder {
		TextView lessonNo;
		TextView lesson;
		LinearLayout item;
	}

	public void setSelectedItem(int ind) {
		selectedIntdex = ind;
		notifyDataSetChanged();

	}
}
